home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / pennmush.000 / pennmush-1.50-p8-linux.tar / pennmush / player.c < prev    next >
C/C++ Source or Header  |  1993-04-06  |  4KB  |  155 lines

  1. /* player.c */
  2.  
  3. #include "copyright.h"
  4. #include <string.h>
  5. #include <sys/time.h>
  6. #include <sys/types.h>
  7.  
  8. #include "config.h"
  9. #include "db.h"
  10. #include "interface.h"
  11. #include "externs.h"
  12.  
  13.  
  14. extern char *ctime();
  15.  
  16. int password_check(player, password)
  17.      dbref player;
  18.      char *password;
  19. {
  20.   ATTR *a;
  21.  
  22.   /* read the password and compare it */
  23.   if ((a = atr_get_noparent(player, "XYXXY")) &&
  24.       strcmp(uncompress(a->value), password) &&
  25.       strcmp(crypt(password, "XX"), uncompress(a->value)))
  26.     return 0;
  27.  
  28.   /* prevent direct entry of the raw encrypted password */
  29.   if ((strlen(password) == 13) &&
  30.       (password[0] == 'X') && (password[1] == 'X'))
  31.     return 0;
  32.  
  33.   /* we're okay */
  34.   return 1;
  35. }
  36.  
  37. dbref connect_player(name, password)
  38.     const char *name;
  39.     const char *password;
  40. {
  41.   dbref player;
  42.  
  43.   /* validate name */
  44.   if ((player = lookup_player(name)) == NOTHING)
  45.     return NOTHING;
  46.  
  47.   /* validate password */
  48.   if (!password_check(player, password))
  49.     return NOTHING;
  50.  
  51.   db[player].parent = NOTHING;
  52.   return player;
  53. }
  54.  
  55. dbref create_player(name, password, host)
  56.      const char *name;
  57.      const char *password;
  58.      const char *host;
  59. {
  60.   dbref player;
  61.   time_t tt;
  62.   char *s;
  63.   if (!ok_player_name(name) || !ok_password(password))
  64.     return NOTHING;
  65.  
  66.   /* else he doesn't already exist, create him */
  67.   tt = time((time_t *) 0);
  68.   s = ctime(&tt);
  69.   s[strlen(s) - 1] = 0;
  70.   player = new_object();
  71.  
  72.   /* initialize everything */
  73.   SET(db[player].name, name);
  74.   db[player].location = PLAYER_START;
  75.   db[player].exits = PLAYER_START;    /* home */
  76.   db[player].owner = player;
  77.   db[player].parent = NOTHING;
  78.   db[player].flags = TYPE_PLAYER;
  79.   db[player].flags |= options.player_flags;
  80.   db[player].toggles |= options.player_toggles;
  81.   s_Pass(player, crypt(password, "XX"));
  82.   giveto(player, START_BONUS);    /* starting bonus */
  83.   (void) atr_add(player, "LAST", s, GOD, NOTHING);
  84.   (void) atr_add(player, "LASTSITE", host, GOD, NOTHING);
  85. #ifdef QUOTA
  86.   (void) atr_add(player, "RQUOTA", START_QUOTA, GOD, NOTHING);
  87. #endif /* QUOTA */
  88.   /* link him to PLAYER_START */
  89.   PUSH(player, db[PLAYER_START].contents);
  90.  
  91.   add_player(player, NULL);
  92.  
  93.   return player;
  94. }
  95.  
  96. void do_password(player, old, newobj)
  97.     dbref player;
  98.     const char *old;
  99.     const char *newobj;
  100. {
  101.  
  102. #ifdef GUEST_RESTRICT
  103.   if (Guest(player)) {
  104.     notify(player, "Guests may not change their passwords.");
  105.     return;
  106.   }
  107. #endif
  108.  
  109.   if (!password_check(player, old)) {
  110.     notify(player, "Sorry");
  111.   } else if (!ok_password(newobj)) {
  112.     notify(player, "Bad new password.");
  113.   } else {
  114.     s_Pass(player, crypt(newobj, "XX"));
  115.     notify(player, "Password changed.");
  116.   }
  117. }
  118.  
  119. void check_last(player, host)
  120.      dbref player;
  121.      const char *host;
  122. {
  123.   time_t tt;
  124.   char *s;
  125.   ATTR *a;
  126.   ATTR *h;
  127.   char last_time[MAX_COMMAND_LEN / 8];
  128.   char last_place[MAX_COMMAND_LEN / 8];
  129.  
  130.   tt = time((time_t *) 0);
  131.   s = ctime(&tt);
  132.   s[strlen(s) - 1] = 0;
  133.   /* compare to last connect see if player gets salary */
  134.   a = atr_get_noparent(player, "LAST");
  135.   if (a && (strncmp(uncompress(a->value), s, 10) != 0))
  136.     giveto(player, PAY_CHECK);
  137.  
  138.   /* tell the player where he last connected from */
  139.   h = atr_get_noparent(player, "LASTSITE");
  140.   if (h) {
  141.     strcpy(last_place, uncompress(h->value));
  142.     strcpy(last_time, uncompress(a->value));
  143.     notify(player, tprintf("Last connect was from %s on %s.",
  144.                last_place, last_time));
  145.   }
  146.   /* if there is no Lastsite, then the player is newly created.
  147.    * the extra variables are a kludge to work around some weird
  148.    * behavior involving uncompress.
  149.    */
  150.  
  151.   /* set the new attributes */
  152.   (void) atr_add(player, "LAST", s, GOD, NOTHING);
  153.   (void) atr_add(player, "LASTSITE", host, GOD, NOTHING);
  154. }
  155.